package com.congee02;

public class UniquePathsWithObstacles_TL {

    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;
        if (obstacleGrid[m - 1][n - 1] == 1 || obstacleGrid[0][0] == 1) {
            return 0;
        }
        return process(obstacleGrid, m, n, 0, 0);
    }

    private int process(int[][] obstacleGrid, int m, int n, int x, int y) {
        if (x >= m || y >= n || obstacleGrid[x][y] == 1) {
            return 0;
        }
        if (x == m - 1 && y == n - 1) {
            return 1;
        }
        return process(obstacleGrid, m, n, x + 1, y) + process(obstacleGrid, m, n, x, y + 1);
    }

}
